//使用layui
var pagesize=10;
layui.config({
    base: '/static/js/layuiModulesEX/'//配置layui路径
});
layui.use(['paging', 'form'], function () {
    var $ = layui.jquery,
        paging = layui.paging(),
        layerTips = parent.layer === undefined ? layui.layer : parent.layer, //获取父窗口的layer对象
        layer = layui.layer, //获取当前窗口的layer对象
        form = layui.form();

    paging.init({
        openWait: true,
        url: '/notice/findByCondition',
        elem: '#content', //内容容器
        params: { //发送到服务端的参数
            schoolid:adminDetail.school.id
        },
        contentType: "application/json; charset=utf-8",
        type: 'POST',
        tempElem: '#tpl', //模块容器
        pageConfig: { //分页参数配置
            elem: 'paged', //分页容器
            pageSize: pagesize, //分页大小
        },
        success: function () { //渲染成功的回调
            //alert('渲染成功');
        },
        fail: function (msg) { //获取数据失败的回调
            //alert('获取数据失败')
        },
        complate: function () { //完成的回调
            //绑定所有编辑按钮事件
            $('#content').children('tr').each(function () {
                //获取每行记录的id值
                var $that = $(this).children('td:last-child');
                var id = $that.children('a[data-opt=more]').data('id');
                // console.log(id);
                $that.children('a[data-opt=more]').on('click', function () {
                    vm.show = false;
                    axios.get('/notice/findById/' +id)
                        .then(function (response) {
                            console.log(response.data.data);
                            vm.notice = response.data.data.notice;
                            vm.composerName = response.data.data.composerName;
                            var divshow = $("#hello");
                            divshow.text("");// 清空数据
                            // divshow.append(vm.notice.content); // 添加Html内容，不能用Text 或 Val
                            divshow.html(vm.notice.content);
                        })
                        .catch(function (response) {
                            console.log(response);
                        });

                });
                $that.children('a[data-opt=delete]').on('click', function() {
                    layer.confirm('确认删除？',function (index) {
                        axios.get('/notice/removeById/'+id)
                            .then(function (response) {
                                console.log(response);
                            })
                            .catch(function (response) {
                                console.log(response);
                            });
                        layer.close(index);
                        location.reload();

                    });

                    // var id = $that.children('td:fisrt-child').children('input[type=checkbox]').data('id');
                    // layer.msg(id);
                    // layer.msg(id);
                });

            });

        }
    });
    var vm = new Vue({
        el: '#Vue',
        data: {
            show: true,
            notice: {
                publisherid:publisherid
            },
            composerName:""
        },
        methods: {

            /**
             * 返回按钮
             */
            reload: function () {
                vm.show = true;
                vm.getInfo(vm.notice.id);
            },
            /**
             * 获取信息
             * @param publisherid
             */
            getInfo: function (publisherid) {
                $.ajax({
                    type: "GET",
                    url: "/notice/findById/" +vm.notice.id,
                    dataType: "json",
                    success: function (Response) {
                        console.log(Response.data);
                       vm.notice = Response.data.data;

                    },
                    error: function (msg) {
                        console.log("失败");
                        console.log(msg);
                    }
                });
            }
        }
    });


});